/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gamedsl2.impl;

import gamedsl2.AbstractEnvironment;
import gamedsl2.Entity;
import gamedsl2.Gamedsl2Package;
import gamedsl2.State;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Abstract Environment</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gamedsl2.impl.AbstractEnvironmentImpl#getState <em>State</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEnvironmentImpl#getEntities <em>Entities</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEnvironmentImpl#getGravityForce <em>Gravity Force</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEnvironmentImpl#getGravityDirection <em>Gravity Direction</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class AbstractEnvironmentImpl extends EObjectImpl implements AbstractEnvironment {
	/**
	 * The cached value of the '{@link #getEntities() <em>Entities</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntities()
	 * @generated
	 * @ordered
	 */
	protected EList<Entity> entities;

	/**
	 * The default value of the '{@link #getGravityForce() <em>Gravity Force</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGravityForce()
	 * @generated
	 * @ordered
	 */
	protected static final float GRAVITY_FORCE_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getGravityForce() <em>Gravity Force</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGravityForce()
	 * @generated
	 * @ordered
	 */
	protected float gravityForce = GRAVITY_FORCE_EDEFAULT;

	/**
	 * The default value of the '{@link #getGravityDirection() <em>Gravity Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGravityDirection()
	 * @generated
	 * @ordered
	 */
	protected static final float GRAVITY_DIRECTION_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getGravityDirection() <em>Gravity Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGravityDirection()
	 * @generated
	 * @ordered
	 */
	protected float gravityDirection = GRAVITY_DIRECTION_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AbstractEnvironmentImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Gamedsl2Package.Literals.ABSTRACT_ENVIRONMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State getState() {
		if (eContainerFeatureID() != Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE) return null;
		return (State)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetState(State newState, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newState, Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setState(State newState) {
		if (newState != eInternalContainer() || (eContainerFeatureID() != Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE && newState != null)) {
			if (EcoreUtil.isAncestor(this, newState))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newState != null)
				msgs = ((InternalEObject)newState).eInverseAdd(this, Gamedsl2Package.STATE__ENVIRONMENT, State.class, msgs);
			msgs = basicSetState(newState, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE, newState, newState));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Entity> getEntities() {
		if (entities == null) {
			entities = new EObjectContainmentWithInverseEList<Entity>(Entity.class, this, Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES, Gamedsl2Package.ENTITY__ENVIRONMENT);
		}
		return entities;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getGravityForce() {
		return gravityForce;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGravityForce(float newGravityForce) {
		float oldGravityForce = gravityForce;
		gravityForce = newGravityForce;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_FORCE, oldGravityForce, gravityForce));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getGravityDirection() {
		return gravityDirection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGravityDirection(float newGravityDirection) {
		float oldGravityDirection = gravityDirection;
		gravityDirection = newGravityDirection;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_DIRECTION, oldGravityDirection, gravityDirection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetState((State)otherEnd, msgs);
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getEntities()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				return basicSetState(null, msgs);
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				return ((InternalEList<?>)getEntities()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				return eInternalContainer().eInverseRemove(this, Gamedsl2Package.STATE__ENVIRONMENT, State.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				return getState();
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				return getEntities();
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_FORCE:
				return getGravityForce();
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_DIRECTION:
				return getGravityDirection();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				setState((State)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				getEntities().clear();
				getEntities().addAll((Collection<? extends Entity>)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_FORCE:
				setGravityForce((Float)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_DIRECTION:
				setGravityDirection((Float)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				setState((State)null);
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				getEntities().clear();
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_FORCE:
				setGravityForce(GRAVITY_FORCE_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_DIRECTION:
				setGravityDirection(GRAVITY_DIRECTION_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__STATE:
				return getState() != null;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES:
				return entities != null && !entities.isEmpty();
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_FORCE:
				return gravityForce != GRAVITY_FORCE_EDEFAULT;
			case Gamedsl2Package.ABSTRACT_ENVIRONMENT__GRAVITY_DIRECTION:
				return gravityDirection != GRAVITY_DIRECTION_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (gravityForce: ");
		result.append(gravityForce);
		result.append(", gravityDirection: ");
		result.append(gravityDirection);
		result.append(')');
		return result.toString();
	}

} //AbstractEnvironmentImpl
